import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router'
import { LoginRoute, PathMatchRoute, RootRoute } from '@/router/routes'
import { App } from 'vue'
import { createRouterGuard } from '@/router/guard'

const { VITE_ROUTE_HASH = 'Y' } = import.meta.env

export const constantRoutes: RouteRecordRaw[] = [LoginRoute, RootRoute, PathMatchRoute]

const router = createRouter({
  history: VITE_ROUTE_HASH === 'y' ? createWebHashHistory() : createWebHistory(),
  routes: constantRoutes,
  scrollBehavior: () => ({ left: 0, top: 0 })
})

export async function setupRouter(app: App) {
  app.use(router)
  createRouterGuard(router) // 配置路由导航守卫设置
  await router.isReady()
}

export default router
